<style>
.{{$t|escape:'html'}}_image_button {
  cursor: pointer;
}
table.{{$t|escape:'html'}}_list {
  width: 600px;
  border-left: 1px solid #dddddd;
  border-top: 1px solid #dddddd;
  margin-bottom: 1px;
  font-size: 11px;
}
table.{{$t|escape:'html'}}_list td.border {
  border-right: 1px solid #dddddd;
  border-bottom: 1px solid #dddddd;
}
table.{{$t|escape:'html'}}_list th {
  text-align: left;
  height: 35px;
  background-color: #eaf2f5;
  padding: 5px 0 5px 10px; 
  border-right: 1px solid #ffffff;
  border-bottom: 1px solid #ffffff;
}
table.{{$t|escape:'html'}}_list tr.drop td {
  padding-left: 0;
  border-right: 0;
  border-bottom: 0;
}
table.{{$t|escape:'html'}}_list tr.hi td {
  padding-left: 10px;
  height: 35px;
  background-color: #ff8000;
  border-right: 1px solid #dddddd;
  border-bottom: 1px solid #dddddd;
}
table.{{$t|escape:'html'}}_list tr.rowodd td {
  padding-left: 10px;
  height: 35px;
  background-color: #eeeeee;
  border-right: 1px solid #dddddd;
  border-bottom: 1px solid #dddddd;
}
table.{{$t|escape:'html'}}_list tr.roweven td {
  padding-left: 10px;
  height: 35px;
  border-right: 1px solid #dddddd;
  border-bottom: 1px solid #dddddd;
}
table.{{$t|escape:'html'}}_list tr.rowodd:hover td {
  background-color: #f4f3b2;
}
table.{{$t|escape:'html'}}_list tr.roweven:hover td {
  background-color: #f4f3b2;
}
</style>

<table id="{{$t|escape:'html'}}_payments" class="{{$t|escape:'html'}}_list" cellPadding="0" cellSpacing="0">
  <!--
  <tr>
    <td style="height: 35px;padding-left: 10px;"><input id="{{$t|escape:'html'}}_payments_select" type="checkbox"></input></td>
    <td class="border" style="padding-left: 10px;border-bottom: 0;" colSpan=4>
      <table>
        <tr>
        
          <td><select id="{{$t|escape:'html'}}_payments_actions"><option>{{t escape='html'}}Actions...{{/t}}</option></select></td>
          <td>
            <span class="image_button" style="width: 140px;" onclick="location.href='admin.php?path=ecommerce&t=payment';">
              <table>
                <tr>
                  <td><img src="image/btn/add.png"></img></td>
                  <td>{{t escape='html'}}New Payment{{/t}}</td>
                </tr>
              </table>
            </span>
          </td>
          
        </tr>
      </table>
    </td>
  </tr>
  -->
  <tr>
    <!--<th style="width: 50px;"></th>-->
    <th style="width: 300px;">{{t escape='html'}}Name{{/t}}</th>
    <th style="width: 100px;">{{t escape='html'}}Status{{/t}}</th>
    <th style="border-right: 0;"></th>
  </tr>
</table>

<script src="jsrequest.php?script={{$t|escape:'html'}}" type="text/javascript"></script>
<script type="text/javascript">
  <!--
    if (document.addEventListener) {
      document.addEventListener('DOMContentLoaded', init, false);
    }
    window.onload = init;
    
    var _payments = JSON.parse('{{$payments|@json_encode|escape:'javascript'}}');
    var _move = null;
    var _y = 0;
    var _selects = [];
    
    function init() {
      if (!document.getElementById || !document.createElement || !arguments || arguments.callee._loaded) {
        return;
      }
      arguments.callee._loaded = true;
      
      update_payments_table();
      
      /*
      var select, actions;
      select = document.getElementById('{{$t|escape:'html'}}_payments_select');
      select.onclick = function() {
        for (var idx in  _selects) {
          var obj = _selects[idx];
          if (obj._obj.is_custom == 0) {
            continue;
          }
          obj.checked = this.checked;
        }
      };
      actions = document.getElementById('{{$t|escape:'html'}}_payments_actions');
      actions.options[actions.options.length] = new Option('Delete');
      actions.onchange = function() {
        if (this.selectedIndex == 1) {
          var deletes = [];
          for (var idx in  _selects) {
            var obj = _selects[idx];
            if (obj.checked) {
              deletes[deletes.length] = obj._obj;
            }
          }
          new RequestUtils()._custom('delete_payments', JSON.stringify(deletes), function(result, params) {
            for (var idx in  deletes) {
              var obj = deletes[idx];
              MiscUtils.remove(_payments, obj, null);
            }
            update_payments_table();
            actions.selectedIndex = 0;
          }, {
            php: 'ecommerce/custom.php',
            pos : DOMUtils.findPos(this)
          });
        }
      };
      */
    }
    
    function update_payments_table() {
      var table, tr, td, elm, div, p;
      
      table = document.getElementById('{{$t|escape:'html'}}_payments');
      DOMUtils.removeTableRows(table, 1);
      if (_payments.length == 0) {
        tr = table.insertRow(-1);
        tr.className = 'nohover';
        td = tr.insertCell(-1);
        td.className = 'border';
        td.colSpan = 3;
        td.style.padding = '5px 0 5px 10px';
        td.style.height = '35px';
        td.appendChild(document.createTextNode('{{t escape='javascript'}}No Results Found{{/t}}'));
        
      } else {
        _payments = MiscUtils.sortByOrder(_payments);
        
        for (var idx in _payments) {
          var obj = _payments[idx];
          
          tr = table.insertRow(-1);
          document.body.onmouseup = function(ev) {
            ev = (ev) ? ev : window.event;
            if (!_move) {
              return;
            }
            new RequestUtils()._custom('payment', JSON.stringify(_move), function(result, params) {
              _move = null;
              update_payments_table();
            }, {
              php: 'ecommerce/custom.php',
              pos : [ev.clientX, ev.clientY]
            });
          };
          
          if (_move) {
            tr.style.cursor = 'move';
          }
          
          if (_move && obj.track_id == _move.track_id) {
            tr.className = 'hi';
          } else {
            tr.className = (idx % 2 == 1) ? 'rowodd' : 'roweven';
          }
          /*
          td = tr.insertCell(-1);
          elm = document.createElement('input');
          elm.type = 'checkbox';
          elm._obj = obj;
          _selects.push(elm);
          if (obj.is_custom == 0) {
            elm.disabled = true;
          } else {
            elm.disabled = false;
          }
          td.appendChild(elm);
          */
          
          td = tr.insertCell(-1);
          update_payments_cell(obj, td);
          td.appendChild(document.createTextNode(obj.name));
          
          td = tr.insertCell(-1);
          update_payments_cell(obj, td);
          td.appendChild(document.createTextNode(obj.status == 1 ? 'Available' : 'Not Available'));

          td = tr.insertCell(-1);
          elm = document.createElement('img');
          elm.className = '{{$t|escape:'javascript'}}_image_button';
          elm.src = 'image/edit.png';
          elm._obj = obj;
          elm.onclick = function() {
            location.href = 'admin.php?path=ecommerce&t=payment&pti=' + this._obj.track_id;
          }
          td.appendChild(elm);
        }
      }
    }
    
    function update_payments_cell(payment, td) {
      if (!_move || payment.track_id != _move.track_id) {
        td.style.cursor = 'move';
        td._obj = payment;
        td.onmousedown = function(ev) {
          ev = (ev) ? ev : window.event;
          _move = this._obj;
          update_payments_table();
          _y = ev.clientY;
        };
        td.onmouseover = function(ev) {
          ev = (ev) ? ev : window.event;
          if (OOBTUtils.move(_move, this._obj, _payments, (ev.clientY - _y < 0))) {
            _y = ev.clientY;
            update_payments_table();
          }
        };
      }
    }
  -->
</script>
